package com.spj.controller;

import com.spj.entity.User;
import com.spj.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author :spj
 * @Date:2022/4/5
 * @description:
 */
@RestController
@RequestMapping("UserController")
public class UserController {
    @Autowired
    private UserServiceImpl service;

    @RequestMapping("/User")
    public boolean checkUser(@RequestBody User user, HttpServletRequest request) {
        User userByAP = service.checkUser(user);
        if (userByAP == null) {
            return false;
        } else {
            request.getSession().setAttribute("user", userByAP);
            return true;
        }
    }

    @RequestMapping("/UserTwo")
    public boolean checkUserName(@RequestBody User user) {
        User userByName = service.checkUserName(user);
        if (userByName == null) {
            service.registUser(user);
            return true;
        } else {
            return false;
        }
    }

    @RequestMapping("/UserThree")
    public boolean checkUserName(HttpServletRequest request) {
        request.getSession().removeAttribute("user");
        return true;
    }
}
